﻿using System;
using System.Collections.Generic;
using System.Text;
using DeepHash.Document.Format;
using DeepHash.Document;

namespace DeepHash.Testrun
{
    class Program
    {
        static void Main(string[] args)
        {
            //SaveTest();
            //WalkTest();
            //LoadTest();
            //DiffTest();
            System.Threading.Thread.Sleep(5000);


            PrintHeader("Web 1, Web 2  - WebSite");
            Compare(@"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web1\WebSite.txt",
                @"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web2\WebSite.txt",
                @"C:\K2", @"C:\K2");

            PrintHeader("Web 1, Web 2  - EmailNotification");
            Compare(@"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web1\EmailNotification.txt",
                @"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web2\EmailNotification.txt",
                @"C:\K2", @"C:\K2");

            PrintHeader("Web 1, Web 2  - K2WebService");
            Compare(@"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web1\K2WebService.txt",
                @"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web2\K2WebService.txt",
                @"C:\K2", @"C:\K2");

            PrintHeader("Web 1, Web 2  - Assembly");
            Compare(@"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web1\Assembly.txt",
                @"c:\Documents and Settings\Shafqat\My Documents\WKFS\K2\Diff_Reports\Stg-Web2\Assembly.txt",
                @"c:\WINDOWS", @"c:\WINDOWS");

        }


        private static void PrintHeader(string header)
        {
            Console.WriteLine("\n;==============================================");
            Console.Write(";" + header);
            Console.WriteLine("\n;==============================================");
        }

        private static void Compare(string file1, string file2, string basePath1, string basepath2)
        {
            TextDocumentFormatter textFormatter = new TextDocumentFormatter();
            textFormatter.BasePath = basePath1;
            VerificationDocument prodWeb1Website = VerificationDocument.LoadFromFile(file1,
                (IDocumentFormatter)textFormatter);
            TextDocumentFormatter textFormatter2 = new TextDocumentFormatter();
            textFormatter2.BasePath = basepath2;
            VerificationDocument stageWeb1Website = VerificationDocument.LoadFromFile(file2,
                (IDocumentFormatter)textFormatter2);

            DocumentComparer comparer = new DocumentComparer(prodWeb1Website, "PROD ", stageWeb1Website, "STAGE");
            comparer.Compare();
        }

        private static void DiffTest()
        {
            VerificationDocument baseDoc = VerificationDocument.LoadFromFile(@"C:\test.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());
            VerificationDocument targetDoc = VerificationDocument.LoadFromFile(@"C:\test2.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());

            DocumentComparer comparer = new DocumentComparer(baseDoc, "base", targetDoc, "target");
            comparer.Compare();
        }

        private static void LoadTest()
        {
            VerificationDocument doc = VerificationDocument.LoadFromFile(@"C:\test.hash", (IDocumentFormatter)new XmlDocumentFormatter());
            VerificationDocument textDoc = VerificationDocument.LoadFromFile(@"C:\test.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());
            textDoc.SaveFile(@"C:\test2.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());
            //doc.SaveFile(@"C:\test3.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());
            Console.WriteLine(doc);
        }

        private static void WalkTest()
        {
            DirectoryWalker dw = new DirectoryWalker();
            VerificationDocument doc = dw.WalkDirectory(@"c:\projects", new MD5HashAlgorithem(), true, new DirectoryWalker.DirectoryWalkNotification(WalkNotification));
            doc.SaveFile(@"C:\test.hash.xml", (IDocumentFormatter)new XmlDocumentFormatter());
            doc.SaveFile(@"C:\test.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());

            VerificationDocument docXml = VerificationDocument.LoadFromFile(@"C:\test.hash.xml",
                (IDocumentFormatter)new XmlDocumentFormatter());
            docXml.SaveFile(@"C:\test2.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());
            docXml.SaveFile(@"C:\test3.hash.xml", (IDocumentFormatter)new XmlDocumentFormatter());

            VerificationDocument docTxt = VerificationDocument.LoadFromFile(@"C:\test.hash.txt",
                (IDocumentFormatter)new TextDocumentFormatter());
            docTxt.SaveFile(@"C:\test2.hash.xml", (IDocumentFormatter)new XmlDocumentFormatter());
            docTxt.SaveFile(@"C:\test3.hash.txt", (IDocumentFormatter)new TextDocumentFormatter());


        }

        public static bool WalkNotification(DirectoryWalker.DirectoryWalkInfo info)
        {
            Console.WriteLine("{0}\t\t: {1}", info.Type, info.Path);
            return true;
        }



        private static void SaveTest()
        {
            VerificationDocument doc = new VerificationDocument();
            FileVerificationRecord rec = new FileVerificationRecord();
            rec.Hash = ASCIIEncoding.ASCII.GetBytes("23343434343434");
            rec.Name = "Test";
            doc.Files.Add(rec);

            FolderVerificationRecord folder = new FolderVerificationRecord();
            //folder.Hash = ASCIIEncoding.ASCII.GetBytes("3635279339033");
            folder.Name = "Folder";
            doc.Folders.Add(folder);

            FileVerificationRecord file = new FileVerificationRecord();
            file.Hash = ASCIIEncoding.ASCII.GetBytes("2344343434");
            file.Name = "aa";

            folder.Files.Add(file);

            doc.SaveFile(@"C:\test.hash", (IDocumentFormatter)new XmlDocumentFormatter());

        }
    }
}
